﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DigibizTree.Picker;
using DigibizTree;

namespace DigibizAdvancedMediaPicker
{
    public partial class SelectMediaItem : umbraco.BasePages.BasePage
    {
        public DigibizPickerView digibizPickerView;

        protected override void OnInit(EventArgs e)
        {
            try
            {
                base.OnInit(e);

                int startNodeId = -1;
                int.TryParse(Request.QueryString["startNodeId"], out startNodeId);

                string allowedExtensions = Request.QueryString["allowedExtensions"];
                string allowedMediaTypes = Request.QueryString["allowedMediaTypes"];
                bool selectMultipleNodes = Convert.ToBoolean(Request.QueryString["selectMultipleNodes"]);
                string cropPropertyAlias = Request.QueryString["cropPropertyAlias"];
                string cropName = Request.QueryString["cropName"];
                bool searchEnabled = Convert.ToBoolean(Request.QueryString["searchEnabled"]);
                bool autoSuggestEnabled = Convert.ToBoolean(Request.QueryString["autoSuggestEnabled"]);
                string searchMethod = Request.QueryString["searchMethod"];

                digibizPickerView = new DigibizPickerView();
                digibizPickerView.StartNodeId = startNodeId;
                digibizPickerView.SelectMultipleNodes = selectMultipleNodes;
                digibizPickerView.AllowedExtensions = allowedExtensions;
                digibizPickerView.AllowedMediaTypes = allowedMediaTypes;
                digibizPickerView.IsCreateTree = false;
                digibizPickerView.SelectStartNode = false;
                digibizPickerView.PickerClass = "DigibizPicker clearfix";
                digibizPickerView.CropPropertyAlias = cropPropertyAlias;
                digibizPickerView.CropName = cropName;
                digibizPickerView.SearchEnabled = searchEnabled;
                digibizPickerView.AutoSuggestEnabled = autoSuggestEnabled;
                digibizPickerView.SearchMethod = searchMethod;
                PlaceholderPicker.Controls.Add(digibizPickerView);
            }
            catch (Exception ex)
            {
                DAMP_Helper.LogException(ex);
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "ErrorInit", DigibizConstants.DEFAULTERRORALERT, true);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }
    }
}